﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Enter.Admin.Configs
{
    // https://www.c-sharpcorner.com/article/custom-model-binding-in-asp-net-core-mvc/
    // https://github.com/jignesht24/Aspnetcore/tree/master/CustomModelBinder/ModelBinder/ModelBinder
    // https://www.dotnetcurry.com/aspnet-mvc/1368/aspnet-core-mvc-custom-model-binding
    // https://docs.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-5.0
    //public class DateTimeModelBinder : IModelBinder
    //{
    //    public Task BindModelAsync(ModelBindingContext bindingContext)
    //    {

    //        if (bindingContext == null)
    //            throw new ArgumentNullException(nameof(bindingContext));

    //        var values = bindingContext.ValueProvider.GetValue("Value");
    //        if (values.Length == 0)
    //            return Task.CompletedTask;

    //        var splitData = values.FirstValue.Split(new char[] { '|' });
    //        if (splitData.Length >= 2)
    //        {
    //            var result = new User
    //            {
    //                Id = Convert.ToInt32(splitData[0]),
    //                Name = splitData[1]
    //            };
    //            bindingContext.Result = ModelBindingResult.Success(result);
    //        }

    //        return Task.CompletedTask;
    //    }
    //}
}
